package com.yp.infrastructure.demo.domain.service.impl;

import com.yp.infrastructure.axon.service.BaseAxonService;
import com.yp.infrastructure.mvc.session.UserSession;
import org.axonframework.commandhandling.gateway.CommandGateway;
import org.axonframework.queryhandling.QueryGateway;

import java.util.UUID;

public abstract class AbstractPartnerService extends BaseAxonService {

    private final UserSession userSession;

    public AbstractPartnerService(CommandGateway commandGateway, QueryGateway queryGateway, UserSession userSession) {
        super(commandGateway, queryGateway);
        this.userSession = userSession;
    }

    protected String getPartnerId() {
        if (null == userSession.get())
            return UUID.randomUUID().toString();
        return (String) userSession.get();
    }
}
